package com.ita.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.ita.dao.IBookDao;
import com.ita.vo.Book;
@Repository(value="bookDaoImpl")
public class BookDaoImpl implements IBookDao {

	@PersistenceContext
	private EntityManager em;
	

	public EntityManager getEm() {
		return em;
	}

	public void setEm(EntityManager em) {
		this.em = em;
	}

	@Override
	public int insert(Book book) {
		int line=0;
		em.persist(book);
		line=1;
		return line;
	}

	@Override
	public int update(Book book) {
		int line=0;
		em.merge(book);
		line=1;
		return line;
	}

	@Override
	public List<Book> fuzzyQueryById(String bookid) {
		return null;
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Book> queryAll() {
		Query q=em.createQuery("from Book");
		return q.getResultList();
	}

	@Override
	public int deleteById(String bookid) {
		int line=0;
		Book b=em.find(Book.class, bookid);
		if(b!=null){
			em.remove(b);
			line=1;
		}
		return line;
		
	}

}
